package top.juanshen.print.util;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author yanjuan
 * @date 17/11/8 下午7:01
 */
public class ReadUtil {
    public static  String ReadText(String filePathAndName, String encoding){
        encoding = encoding.trim();
        StringBuffer str = new StringBuffer("");
        String st = "";
        try {
            FileInputStream fs = new FileInputStream(filePathAndName);
            InputStreamReader isr;
            if (encoding.equals("")) {
                isr = new InputStreamReader(fs);
            } else {
                isr = new InputStreamReader(fs, encoding);
            }
            BufferedReader br = new BufferedReader(isr);
            try {
                String data = "";
                while ((data = br.readLine()) != null) {
                    str.append(data);
                }
            } catch (Exception e) {
                str.append(e.toString());
            }
            st = str.toString();
            if (st != null && st.length() > 1){
                st = st.substring(0, st.length());
            }
        } catch (IOException es) {
            st = "";
        }
        return st;
    }
}
